﻿--#include "data\config\title\HeadTitleTriggerConfig.lua"
--#include "data\config\title\HeadTitle.lua" once

-- 称号触发管理


function TitleEventTrigger(sysarg, eventId, param1, param2, param3)
	local cfg = HeadTitleTriggerCfg[eventId]
	if not cfg then
		return
	end
	for idx = 1, #cfg do
		if #cfg[idx].triggerValue == 1 then
			if cfg[idx].triggerValue[1] <= param1 then
				AddHeadTitle(sysarg, cfg[idx].titleId)
			end
		elseif #cfg[idx].triggerValue == 2 then
			if cfg[idx].triggerValue[1] <= param1 and cfg[idx].triggerValue[2] <= param2 then
				AddHeadTitle(sysarg, cfg[idx].titleId)
			end
		elseif #cfg[idx].triggerValue == 3 then
			if cfg[idx].triggerValue[1] <= param1 and cfg[idx].triggerValue[2] <= param2 and cfg[idx].triggerValue[3] <= param3 then
				AddHeadTitle(sysarg, cfg[idx].titleId)
			end
		end
	end
end

function AddHeadTitle(sysarg, titleId)
	local cfg
  	if titleId ~= 0 then
	    for idx = 1, #HeadTitle do
	      	if HeadTitle[idx].titleid == titleId then
	        	cfg = HeadTitle[idx]
	        	break
	      	end
    	end
  	end

  	if(cfg == nil)then
    	return
  	end
	if (Actor.hasTopTitle( sysarg, titleId ) and cfg.titleTime <=0 )then
    	return
  	end
    Actor.addTopTitle( sysarg, titleId )
end




